package cn.rongdao.jrkabao.model.api;

import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.mifengkong.frtools.app.FRApplication;
import com.mifengkong.frtools.http.request.BaseRetrofit;
import com.mifengkong.frtools.util.FRLog;
import com.mifengkong.frtools.util.FRString;

import java.util.HashMap;
import java.util.Map;

import cn.mifengkong.appcommon.util.ChannelUtil;
import cn.rongdao.jrkabao.BuildConfig;
import cn.rongdao.jrkabao.constant.AppConstant;
import cn.rongdao.jrkabao.constant.ServletAddressConstant;
import cn.rongdao.jrkabao.dao.UserDao;

/**
 *
 */

abstract class BaseModel extends BaseRetrofit {

    protected FRApi mServletApi;
    protected Map<String, Object> mParams = new HashMap<>();
    protected static final int DEFAULT_TIME = 60;

    public BaseModel() {
        super();
        mServletApi = mRetrofit.create(FRApi.class);
    }

    @Override
    protected Map<String, String> getCommonMap() {
        Map<String, String> mCommonParams = new HashMap<>();
        mCommonParams.put(AppConstant.ANDROIDKEY, AppConstant.ANDROID);
        mCommonParams.put(AppConstant.VERSIONKEY, getDoMainType().equals(ServletAddressConstant.SU_DAI) ? "3.9.3" : AppConstant.VERSION);
        mCommonParams.put("source_id", ChannelUtil.getChannelName(FRApplication.getInstance()));
        mCommonParams.put("app_union_name", AppConstant.APPUNIONNAME);
        mCommonParams.put("package_name", BuildConfig.APPLICATION_ID);
        mCommonParams.put("uid", FRString.valueOf(UserDao.getInstance().getUserId()));
        mCommonParams.put("user_id", FRString.valueOf(UserDao.getInstance().getUserId()));
        mCommonParams.put("token", FRString.valueOf(UserDao.getInstance().getToken()));
        return mCommonParams;
    }

    protected void addParamStrings(String key, Object value) {
        if (FRString.isEmpty(key)) {
            FRLog.error("key should not be null");
            return;
        }
        mParams.put(key, value);
    }

    private RecyclerView.ViewHolder createHeaderAndFooterViewHolder(View view) {
        return new RecyclerView.ViewHolder(view) {
        };
    }

    protected void addParamStrings(Map<String, String> map) {
        if (null != map && map.size() > 0) {
            mParams.putAll(map);
        }
    }
}
